home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / SWDOS12 / SWDOS.ENG < prev    next >
Text File  |  1995-02-10  |  26KB  |  645 lines

  1.                           Unit SWDOS
  2.            Various tools for DOS calls from Turbo Pascal
  3.                 Copyright (æ) by SoftWeyr, 1994
  4.  
  5.                           INTRODUCTION
  6.  
  7.     This unit contains a large collection of various small, but
  8. useful tools for deal with DOS from Turbo Pascal program. It is
  9. not replacement for DOS unit, but addition to it.
  10.     SWDOS must work in any version of TP higher than 4.0. But I
  11. hadn't tried. Some functions cannot work in versions prior 6.0.
  12. Most of functions  are  compatible with  DOS  3.+, but some  is
  13. specific for DOS 5.+
  14.  
  15.                        REVISION HISTORY
  16.  
  17. July 1994 - first version created.
  18. September 1994  - small bugs fixed, file name handling added.
  19. November 1994 - Incomparibility with TP 7.0 fixed.
  20.                 TEXTSEEK and TEXTOPS routines added.
  21.  
  22.  
  23.                    PROCEDURES AND FUNCTIONS
  24.  
  25.                       I. FILE OPERATION
  26.  
  27.     Procedures  and   functions   in   this  chapter  generally
  28. duplicate corresponding  routines from DOS.TPU, with one little
  29. difference - they expect not file variable as  a parameter, but
  30. string, contains filename or file handle.
  31.     Why?  If  you  work  with   TDosStream   objects   or   its
  32. descendants,  it seems  be  to expansive -  link  all file  I/O
  33. library simply for file deletion or  renaming. Borland includes
  34. PrintStr  procedure  to avoid linking of file  I/O  library  in
  35. Turbo Vision program.
  36.    Also,  this   procedures   never  causes  a  Runtime  Error,
  37. regardless of compilation flags. In case  of  Error  they  sets
  38. value of DOSError variable, declared in DOS unit.
  39.  
  40. I.1 Procedure RenameFile(OldName,NewName:String);
  41.    Renames file
  42. I.2 Procedure EraseFile(FileName:String);
  43.    Erases file.
  44. I.3 Procedure SetFileAttr(FileName:String;Attr:Word);
  45.     Changes attributes. Note, that this procedure is applicable
  46.     to directories.
  47. I.4 Function GetFileAttr(FileName:String):Word;
  48.     Returns attributes. Note, not in var parameter as GetFAttr,
  49.     but  as  a  function  result.  That  allows  you  to  check
  50. attributes without  declaring  two additional variables (one of
  51. type file and second of type word)
  52.  
  53.     All  functions  above  takes  no  care,  is file opened  or
  54. closed. Situation with file creation time is more complicated.
  55.  
  56. I.5. Procedure SetFileTime(FileName:String;DateTime:LongInt);
  57. I.6. Procedure GetFileTime(FileName : String; var DateTime
  58.                                             : Longint);
  59.    This procedures works ONLY if file CLOSED.
  60. If file is open, its handle must exist and be  stored anywhere.
  61. For instance in Handle field if TDosStream object.
  62. In this case use:
  63.  
  64. I.7. Procedure SetHandleTime(Handle:Word;DateTime:LongInt);
  65. I.8. Procedure GetHandleTime(Handle:Word;var DateTime:Longint);
  66.  
  67. (Really  xxxFileTime takes following three steps:
  68.      1. Open file for reading (Access code 0)
  69.      2. Call xxxHandleTime
  70.      3. Close file)
  71.  
  72.                    II. Control of file count
  73.  
  74.     May be, you'd already have Runtime
  75. Error 004 -  to  many  open files. Usially it  means  that  you
  76. somewhere forget to  close files. But sometimes you really need
  77. a lot of files. You press F1 and read:
  78.  
  79. DOS never allows more than 15 open files per
  80. process.
  81.  
  82. If you get this error with less than 15 open
  83. files, the CONFIG.SYS file might not include a
  84. FILES=xx entry (or xx might specify too few
  85. files).
  86.  
  87. Increase the number xx to some suitable value,
  88. such as 20.
  89.  
  90.      But  you  have  FILES=40  or more in your  CONFIG.SYS  and
  91. applications like Paradox or FoxPro can do something with it.
  92.    Really quote  from help above is  false. There is  a special
  93. DOS function,  that let you request as many  files as you need.
  94. Up to  255. I had  read that  you can request  more files  than
  95. declared in CONFIG.SYS, but it seems to be a lie too.
  96.    At least you can obtain as many as you write  in CONFIG.SYS,
  97. if you call procedure:
  98.  
  99. II.1. MaxFiles(Count:Integer)
  100.  
  101.  Where Count -  number of files,  you want plus  five  standard
  102. files:
  103.  
  104.   STDIN  - corresponds  with  INPUT, if you  don't  use CRT  or
  105.            someting simular
  106.   STDOUT - OUTPUT with same restrictions
  107.   STDERR - Console output file  which  cannot  be redirecrd, in
  108.            difference to STDOUT
  109.   STDPRN  - Default printer. Has no relations with pascal LST.
  110.   STDAUX - Default COM port. Usially unusable.
  111.  
  112. All names above aren't DOS file or device name. They are common
  113. symbolic constants for predefined file handles  from  0  to  4.
  114. (these are declared in SWDOS.TPU to)
  115. You can  even close this handles to obtain  some more files for
  116. your own affairs.
  117.     But if you  write  command-line controlled program, you can
  118. find some usage for STDERR.
  119.  
  120.  II.2. Procedure CloseHandle(Hadle:Word);
  121.  
  122.  Allows you to close a file  handle. May be useful, if you want
  123. free up standard  handles  or  if you want to  close  DOS  file
  124. without deallocating corresponding object or buffer.
  125.  
  126.                        III. Standard I/O
  127.  
  128.      If you  write program which uses  STDOut, you may  want to
  129. know, does it write to screen or somewhere else (to  disk file,
  130. for example). If  you doubt, redirect  TPC output to  file  and
  131. look into it with text editor (but not IDE)
  132.  
  133.  
  134.     III.1 Function Redirected(var F:TExt):Boolean;
  135.  
  136. Allows to do this. It returns True, if output comes  to printer
  137. or file, and input from file.
  138.    It is usable only for files, which are assigned to STDOUT or
  139. STDIN (You can  do this by  Assign(F,'') and Rewrite  or  Reset
  140. respectively)
  141.     By default INPUT = STDIN and OUTPUT=STDOUT, but if in first
  142. line of  program you have  uses CRT (TPCRT,OPCRT) or this units
  143. are used  at list of one of  linked units,  this files have  no
  144. relations with any  DOS  devices. But at least  in  TP 6.0 this
  145. function works  correctly with CRT, becouse ASSIGNCRT procedure
  146. doesn't alter Handle field of TextRec structure.
  147.  
  148.     If   you   write    commandline-controlled   program   with
  149. rudimentary interactivity like
  150. File  Already   Exist.
  151. Overwrite?(Y/N), STDERR  standard file can be useful. Sometimes
  152. you  want  to  use  STDPRN  and  even  STDAUX.  There  are  two
  153. procedures for use them:
  154.  
  155. III.2. Procedure OpenSTD(var F:Text;Device:Word);
  156. III.3. Procedure StdWrite(Device:Word;S:String);
  157.  
  158. where Device - one of standard handles. Of couse
  159. DevWrite(STDIN,...)  is   meaningless.  You  wouldn't   recieve
  160. anything except error.
  161.    In  OpenDevice  apart  five  constants  above  you  can  use
  162. constant STDAUXin, which means that you want to open STDAUX for
  163. reading. Due to all other standard devices are either read-only
  164. or write-only, I include call to Reset or Rewrite into OpenSTD
  165.       You aren't need to close this files.
  166.  
  167. And something more for STDOUT. Sometimes it is  good, if output
  168. is visible on screen, even if it is redirected.
  169.  
  170. III.4 Procedure Tee(var F:Text);
  171.  
  172. Allows  to  do this.  It  is  applicable  for  files  which are
  173. assigned via AssignCRT or AssignDevice of Turbo Vision TextView
  174. unit, and  sends to STDOUT  any character, which was written to
  175. this file (if STDOUT is not redirected, you will see all output
  176. twice. I recommend you following sequence
  177.  
  178. Uses Crt;
  179. ...
  180.  
  181. if Redirected(Output) then Tee(Output);
  182.  
  183. or (for Turbo Vision);
  184.  
  185. var T:PTerminal;
  186. .......
  187.  
  188. AssignDevice(Output,T);
  189. Rewrite(T);
  190. if Redirected(Output) then Tee(Output);
  191.  
  192.  Sometimes it is  good  to pause  output  after each screen  of
  193. information. But it is too boring - search through your program
  194. for each Writeln and count them.
  195.  
  196. III.5 Procedure SetPagingMode(var F :Text; H :Integer; Message
  197.                                                       :String);
  198.  
  199. Helps you in this case. It would display a given  Message after
  200. each H  lines and wait for Y or N pressed. If Y was pressed, it
  201. would show  next screen,  and if N, it would  place value 100 -
  202. disk write error into  IOResult.  Compile your program with $I-
  203. and do  not forget to check IOResult, if  you don't really want
  204. your program halt after negative answer.
  205.  
  206. III.6. Procedure EndPagingMode(var F:Text);
  207.  
  208. Finishes Paging mode for specified file.
  209.  
  210. Do not apply SetPagingMode to more than one file at same time!
  211.  
  212.    Reading  from   keyboard  is  reading  from  STDIN.  Borland
  213. preferes to do  it via BIOS, and places corresponding functions
  214. into CRT units. I think, that is out of logic, becouse CRT is
  215. Catode-Ray  Tube i.e phisical screen, not even a console.
  216. In C language corresponding module is much more logically named
  217. CONIO - console input/output.
  218.   I've placed in SWDOS analogues of this functions, which works
  219. via  DOS  and  implemented  as  inline,  becouse they a  almost
  220. shorter than far call.
  221.  
  222. III.7 Function DOSReadKey:Char;
  223.  
  224. Full analogue of ReadKey
  225.  
  226. III.8 Function ReadKeyWithEcho:Char;
  227.  
  228. No comments
  229.  
  230. III.9 Function DOSKeyPressed:Boolean;
  231.  
  232. Analogue of  KeyPressed (longest function of these three)
  233.  
  234. And some more about reading. Sometimes  useful  to  get  string
  235. from  file  as  function  result, for example to  uppercase  it
  236. before storing anywhere.
  237.  
  238. III.10  Function GetStr(var F:Text):String;
  239.  
  240. Simply perform Readln(F,String_variable) and return result.
  241.  
  242.                IV.Dealing with Environment ¿ PSP
  243.  
  244.     I hope, you know, what is DOS Environment. It is  that very
  245. place, where COMSPEC, PATH and  other  simular  information  is
  246. stored.
  247.     Becouse each program  have its own copy of environment, you
  248. usially  wish  to modify it, only  if  you want to start  child
  249. process.
  250.     For instance many applications add  its  name  to  prompt,
  251. when they calls DOS Shell.
  252.     But  there  are  some  utilities  which   can  return  some
  253. information in envronment variables. How?
  254.  
  255.  
  256. There  is  a pointer  to  Environment block  in  PSP -  program
  257. segment prefix, which every program  has.  In  this prefix also
  258. located command line and some other information.
  259.   Among this  information  any process, except COMMAND.COM (not
  260. only root,  but any copy) has a  pointer to  PSP of its  parent
  261. process. Therefore, environment of parent is accessible, and if
  262. you change it,  this changes would be visible after termination
  263. of your process.
  264.     You can  also  access  Environment  of  first(root) copy of
  265. COMMAND.COM.  It  is  nearly  unusable  for   users  of  Norton
  266. Commander and other such shells, becouse  program, started from
  267. shell, inherits Environment of Shell, not of root COMMAND.COM.
  268.     But root Environment always  have  more free space than any
  269. other,  becouse  it  size  is exactly that value,  which  you'd
  270. specified  in   CONFIG.SYS   SHELL   command,   but  any  other
  271. environment is truncates on nearest paragraph after end of last
  272. variable. (It is reason, why  complicated  batch  files  cannot
  273. work under NC)
  274.     However,  if  you   can  access  PSP  of  parent,  you  can
  275. also look into another its field, like command line.
  276.    Once I've had used such strange way to pass information from
  277. child to parent.
  278.  
  279.   All  functions,   of   SWDOS,  which  deal  with  Environment
  280. and  PSP,  access  "current"  PSP  and  Environment. It is  not
  281. always Environment and PSP of current program. It can be set by
  282. following procedures:
  283.  
  284. IV.1 AccessCurrentEnv
  285.    Make environment of your own program current (default)
  286.  
  287. IV.2 AccessParentEnv
  288.    Make environment of parent current
  289. IV.3 AccessRootEnv - ñ« ¬«α¡Ñó«ú«.
  290.    Make environment of root COMMAND.COM current
  291.  
  292. However  all  environment related procedures of DOS and  System
  293. units (ParamStr,  EnvStr,  EnvCount,  GetEnv) always works with
  294. Environment  of  your program.
  295. (Why ParamStr is among
  296. Environment-related routines? Have you tried to call
  297. ParamStr(0)? (But do not compile  into  memory,  when you would
  298. try, becouse it would give strange results))
  299.  
  300. What can you do with Environment?
  301.  
  302. IV.4. Procedure FreeEnv;
  303.  
  304.     First,  destroy   it   at   all.   Return   this  block  of
  305. memory to DOS for any  other  usage. It is recommended, if  you
  306. write a  TSR program. But if  you destroy Environment  of other
  307. process, you have a chance to hang your system.
  308.  
  309. IV.5. Function GetEnvSize:word;
  310.     Ask a size of it (in bytes)
  311. IV.6. Function GetEnvCount:Integer;
  312.     Number of lines
  313. IV.7. Function GetEnvSpace:word;
  314.     Number of free bytes
  315. IV.8. Function GetEnvStrN(N:Integer):String;
  316.     Get line number N
  317. IV.9. Function GetEnvStr(VarName:String):String;
  318.     Or value  of  given  variable.  Prevouis  function  returns
  319.     string like VARNAME=value, but this - value only.
  320.  
  321. IV.10.Procedure   SetEnvStr(VarName,Value:String);
  322.     At  last,  change  value  or  add  new variable, or  delete
  323.     existing, exactly as DOS command  SET  does.  When SET says
  324.     "Out of environment space" this procedure would return 8 in
  325.     DOSError
  326. IV.11.Function GetProgName:String;
  327.     Get full path to environmemt owner's executable file (if it
  328.     is not COMMAND.COM)
  329.  
  330.     Following   functions   retrieve   information   not   from
  331.     Environment, but from PSP
  332. IV.12. Function GetCommandLine:String;
  333.     Get command line (whole, not bu pieces like ParamStr)
  334. IV.13. Function CommandLineAddress:Pointer;
  335.     Get address of command line, for example for changing it.
  336.     (Returned value really has type ^Strinf[127])
  337. IV.14.Function OldInt22H:Pointer;
  338. IV.15.Function OldInt23H:Pointer;
  339. IV.16.Function OldInt24H:Pointer;
  340.    Get   addresses   of   termination   routine   (int    22H),
  341.    Ctrl-Break handler  (int  23H)  and  critical error handler,
  342.    which were active before start of process, whose environment
  343.    is  now  accessed (for current program they  are  equial  to
  344.    SaveIntXX variables in System unit)
  345.  
  346.                V. Dealing with DOS memory manager
  347.  
  348.     You, of course, know,  that  free memory, which is returned
  349. by MemAvail and can be used by New and GetMem, is not free for
  350. DOS, but is in your program posession. Therefore, if you didn't
  351. limit heap size by $M directuve, you cannot ask dos  to perform
  352. anything, which requires some memory. (for example load another
  353. program by  Exec). Your attempt would  cause only value  8 (Not
  354. enough memory)in DosError.
  355.   But I'm miser. I won't limit  myself in heap usage and I want
  356. to give memory to DOS only if it really needed. Note, that when
  357. you call child process or DOS  Shell, you must save to disk all
  358. what possible, therefore you can free up some memory.
  359.   Memory unit of Turbo Vision have procedure SetMemTop for this
  360. purpose.  But  if you  hate  Turbo  Vision,  you  can  use same
  361. procedure from SWDOS.
  362.  
  363. V.1. Procedure SetMemTop(MemTop:Pointer);
  364.  
  365.   This is designed only for TP version 6.0 and 7.0, real mode.
  366. In protected mode you don't need it at all, becouse all memory,
  367. which free for you is also  free for DPMI. Versions 4.x and 5.x
  368. have  another  heap  manager  and shrinking of memory  in  this
  369. versions is more complicated task. But it is  possible. You can
  370. find it in Turbo  Professional  or Object Professional by Turbo
  371. Power (unit TPDOS/OPDOS, procedure SetBlock).
  372.   But SWDOS  is designed for  newer versions, and I won't waste
  373. my time,  trying to understand  old heap manager. It is enough,
  374. that I didn't  use inline assembler, to allow SWDOS compilation
  375. in old versions.
  376.    You   can   give   all   free   heap   space   to   DOS   by
  377. SetMemTop(HeapPtr) and obtain it back by SetMemTop(HeapEnd).
  378.    You also may want to use  nearly all memory and leave to DOS
  379. only  a  small piece.  For  example to  open  more files  using
  380. MaxFiles procedure. Becouse you don't  know,  how  many  memory
  381. would be
  382. free when  your program would run next time  (it is depended of
  383. loaded  TSR's,  DOS version  etc),  it  is  better  to  get all
  384. availiable memory and then free some amount.
  385.   I usially use following sequence:
  386.     Dec(LongInt(HeapEnd),$400000);
  387.     {decrease heap end segment by $40, i.e 1 Kb}
  388.     SetMemTop(HeapEnd);
  389.     {Return memory above new HeapEnd to DOS}
  390.  
  391. But if  you have memory, which is  free at  DOS level, you  may
  392. wish to use it yourself. Use:
  393.  
  394. V.2 Function DOSAlloc(var Size:Longint):Pointer;
  395.  
  396. to obtain memory block from DOS and:
  397.  
  398. V.3 Procedure DOSFree(P:Pointer);
  399.  
  400. To  free  it. (all memory blocks, allocated  by  your  program,
  401. would be freed when your program is terminated);
  402.    Last procedure  sometimes  returns code 204 (invalid pointer
  403. operation) in DOSError.
  404.   It means that you pass incorrect pointer to it (pointer which
  405. have nonzero offset)
  406.  
  407.   Now some words about  more  fine things, which are availiable
  408. only from DOS 5.0 and higher - about Upper memory blocks (UMB)
  409.   You  can  control  their  allocation  by  setting  allocation
  410. strategy. (see constants msXXXX in SWDOS.PAS)
  411.   You can set allocation strategy by:
  412.  
  413. V.4. Procedure SetAllocationStrategy(Strategy:Word);
  414.  
  415. It  is  strictly recommended to obtain old allocation  strategy
  416. before setting your own by:
  417.  
  418. V.5. Function GetAllocationStrategy:Word;
  419.  
  420. and restore it before termination, becouse if you set strategy
  421. msFirstFitHighOnly, poor DOS  would  try to load any subsequent
  422. program into UMB.
  423.  
  424.  But there is another thing - global enabling/disabling of UMB.
  425. I  don't  know,  how  it  corresponds  with prevouis couple  of
  426. functions, but there is an interface:
  427.  
  428. V.6. Function GetUMBLink:Boolean;
  429. V.7. Procedure SetUMBLink(Allow:Boolean);
  430.  
  431.  
  432.                   VI. UpCase International Ltd
  433.  
  434.     I suppose, each programmer, except native English, was very
  435. angry, when he learn, that  Upcase  function  even in localized
  436. Borland Pascal doesn't understand national symbols.
  437.     DOS is more clever in this case. If you write in your
  438. CONFIG.SYS COUNTRY=xxx, you teach it do this.
  439.     If you would use DOS  function  to  Upcase characters, your
  440. future user  from other country  wouldn't be angry with you for
  441. strange opinion of your program about capitalizing of letters.
  442.  
  443.  
  444. VI.1. Function UpCase(ch:Char):Char;
  445.  
  446.    Replaces function of System unit
  447.  
  448. VI.2. Function StUpCase(S:String):String;
  449.  
  450.   Upcases    whole     string    (replaces    function     from
  451. TPString/OPString, which  is  more clever then standard Upcase,
  452. but  not  clever  enough.  For example, it  doesn't  understand
  453. Russian)
  454.  
  455. VI.3. Procedure UpcaseStr(Str:PChar);
  456.  
  457.  Uppercases ASCIIZ (null-terminated  string). Replaces function
  458. from Strings unit. Version 7.0 only.
  459.  
  460. ATTENTION! DOS calls, which used  by  this  function were first
  461. documented in DOS 5.0. It seems to work in MS-DOS 3.30, but may
  462. not work  in DOSes of another  vendors like COMPAQ  in versions
  463. prior 5.00. It surely doesn't work in Compaq DOS 3.31.
  464.  
  465.                       VII. Temporary files
  466.      DOS can create temorary files with unique names.
  467. You  may  say:  why  do  anything with  it?  I  woudld  give my
  468. temporary file name  like  CLUST$$$$$.$$$ and nobody would have
  469. an idea to overwrite it. But what happens,  when somebody would
  470. try to start two copies of your program in different windows of
  471. Windows, or in same shared directory on network?
  472.  
  473. You can use this possibility by:
  474.  
  475. VII.1 Procedure AssignTemp(var F;TempDir:String);
  476.  
  477.  This  procedure  creates,   but   not  opens,  (more  exact  -
  478. immediately closes) temorary file in given directory.
  479. You can open it by usial Rewrite, write  something there, Reset
  480. it, read etc.
  481.    When you  don't need it anymore,  erase it after  closing or
  482. close by CloseTemp
  483.    File can be either text or binary.
  484.  
  485. VII.2 Procedure CloseTemp(var F:Text);
  486.  
  487.  Simply subsequentual Close(F), Erase(F)
  488.  
  489. Sometimes you may wish to know name of this temporary file, for
  490. instance to pass it to child process.
  491.    Use :
  492.  
  493. VII.3 Function GetFileName(var F):String;
  494.  
  495.  This function retrieves  file name from Text or File variable,
  496. like IDE does when you place such variable into Watch window.
  497.  
  498.  
  499.                      VIII. More about names
  500.  
  501.     There  are  some useful operations, which can be  performed
  502. with file name before opening it. (Substitute default extension
  503. for example). There are no such functions in RTL. You  can find
  504. something in  Turbo/Object  Professional,  but first, there are
  505. some bugs there (for example if pathname contain directory with
  506. extension, it wouldn't work correctly), second,  not every user
  507. of Turbo Pascal has a licensed copy of TPro or OPro.
  508.  
  509. VIII.1 Function JustFileName(FileName:String):String;
  510.    Removes path, if any from file name
  511.  
  512. VIII.2 Function JustName(FileName:String):String;
  513.    Removes path and extension
  514.  
  515. VIII.3 Function JustExtension(FileName:String):String;
  516.    Returns bare extension
  517. VIII.4 Function JustPathName(FileName:String):String;
  518.    Returns bare path  (like for pass to ChDir)
  519.    if you want to add name to this path, do not forget to check
  520.    for trailing'\'
  521.  
  522. VIII.5 Function DefaultExtension(FileName,Extension:String)
  523.                                        :String;
  524.    If file name has no extension, substitutes given
  525.  
  526. VIII.6 Function ForceExtension(FileName,Extension:String)
  527. :String;
  528.    Replaces old extension by given
  529.  
  530. VIII.7 Function ExpandFileName(FileName,DefaultExt,
  531.              DefaultDir:String):String;
  532.    Substitutes  extension  and  search  file in given  list  of
  533. directories (separated by ; ). If  nothing appropriate, returns
  534. empty string.
  535.  
  536.                 IX. Text file handling
  537.  
  538.     Every Turbo Pascal knows, that Text type is not File of
  539. char.  Text   files   are   bufferized,   they   have  flexible
  540. input/output technic, which allows to  use  not  only DOS files
  541. and devices,  but such things as CRT or  Turbo Vision window to
  542. text I/O.
  543.     But, so useful procedures as
  544. Seek, FilePos ¿ FileSize unapplicable for them. You can use
  545. FindFirst  instead  of filesize, but you can  do  nothing  with
  546. positioning of text file. Evidently you  cannot position devise
  547. except this  device own way like  GotoXY. But random  access to
  548. DOS text files is very nice thing.
  549.  
  550.   Now get it:
  551. IX.1 procedure TextSeek(var F:Text;Position:Longint);
  552.  
  553.   Positions text file.  As all other procedures which deal with
  554. text files, set IOResult in  case  of error. File must be  open
  555. for reading (by Reset)
  556.  
  557. IX.2 function  TextPos(var F:Text):Longint;
  558.  
  559.  Returns current postion in bytes. In case of error, returns -1
  560.  
  561.        Sometimes it  is  good  to  write  some information into
  562. memory block  by writeln and  then pass this block, for example
  563. in Turbo Vision TMemo object.
  564.  
  565. IX.3.    procedure    AssignMemory(var   F:Text;Buffer:Pointer;
  566.         BufSize:Word);
  567.  
  568. Allows  to  open file situated in  memory.  You can open it  by
  569. usial Reset  or Rewrite,  but if you want to  read from it, you
  570. must supply BufSize useful characters in buffer.
  571.  Closed by usial Close, but if buffer is dynamically allocated,
  572. do not forget dispose it.  May  be  CloseLoaded procedure below
  573. would be suitable.
  574.  
  575. IX.4 Procedure LoadFile(var F:Text; FileName:String);
  576.  
  577. Loads text file into memort  and  performs  AssignMemory.  Very
  578. useful,  if  you want to have multiple  passes,  becouse  there
  579. wouldn't be any disk I/O, even when you Reset this file.
  580. First Reset performs itself.
  581.    Close this file by  CloseMemory  becouse you don't know size
  582. of buffer, which was allocated for this file.
  583.    If  file was  larger  then 64K or  not  enough free  memory,
  584. returns 8 in IOResult and opens file without loading.
  585.  
  586. IX.5. Procedure CloseLoaded(var F:Text)
  587.  
  588. Closes file and disposes buffer. Usable  not  only  for  files,
  589. opened by LoadFile, but  also  for files, which has dynamically
  590. allocated buffer, which was set by SetTextBuf.
  591.  
  592.                      X. Single Drive systems
  593.  
  594.     If you  had worked on sistem with one  floppy, you have had
  595. already seen a message
  596.  
  597.    Insert disk for drive ... and strike any key.
  598.  
  599. There is  nothing  wrong  for  simple  command-line  controlled
  600. programs,  but  if  you  have complicated user  interface  with
  601. carefully  maintained  screen,  you  would  hate  all  unwanted
  602. messages.
  603.     What can  you do to intercert control of  this. How can you
  604. check - has drive more than one letter,
  605.         which letter is used now,
  606. how can you tell DOS, that drive is now B not A, or vise versa?
  607.  
  608. X.1. Function IsDriveMappable(Drive:Byte):Boolean;
  609.   Recieves drive code (0 - current, 1-A, 2-B etc) and
  610.   returns true if more than one letter corresponds this drive
  611.  
  612. X.2. Function GetDriveLetter(Drive:Byte):char;
  613.   Recieves drive code and returns letter of this drive.
  614.   You  may  also use  this  function to  check  which drive  is
  615. currend. If current drive is C:, GetDriveLetter(0) returns 'C',
  616. even there is nothing to do with changing letters.
  617.  
  618. X.3. Procedure SetDriveLetter(Drive:char);
  619.  
  620. You can use this function to tell DOS, that floppy drive is now
  621. used as A: or B:, regardless of its own opinion.
  622.  
  623.      But nothing happen, if you would try to  set letter, which
  624. does not really correspond with mappable device.
  625.  
  626.  
  627.                    PROTECTED MODE USER NOTES
  628.  
  629.     SWDOS unit was designed to work in real mode. But there are
  630. no real objections to use some functions in  protected mode and
  631. even  Windows.  (but SWDOS  uses  DOS  unit  and  there  are no
  632. DOS.TPW. Due  to this you must change uses  DOS to uses WINDOS,
  633. becouse  the  only accessed thing from this  unit  is  DOSError
  634. variable and FSearch function in ExtentFileName)
  635.     You cannot use in Protected mode
  636.     1. All memory management routines (but WinAPI unit provides
  637.        more suitable routines)
  638.     2. All environment-related routines. It can be siginificant
  639.        lack, but  really  only  procedures AccessXXXEnv FreeEnv
  640.        and getEnvSize  are  prohibited.  If you compute correct
  641.        selector for environment block and place  it in variable
  642.        Environment, you can use other procedures.  But it seems
  643.        to me, that you must also rewrite GetEnvSize, becouse it
  644.        is often called from other routines.
  645.